home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / database / dg53.zip / DGMAN < prev    next >
Text File  |  1997-05-26  |  49KB  |  1,126 lines

  1. Release 53  Last change: 970506   Last Document Update: 970506
  2.  
  3. DG                   USER COMMANDS                       DG
  4.  
  5. *
  6. NAME
  7.      dg - Data-Grep.  Like grep but for searching a free-form
  8.      flatfile database, printing the entire records rather than
  9.      just the lines containing the searched-for phrase.
  10.      Pronounced "dig" as in "digging out data."
  11.  
  12. *
  13. SYNOPSIS
  14.      dg [-options] srchstrng infile 
  15.         srchstring is optional (& ignored) with -s, -l, -U options
  16.         srchstring is optional (not ignored) with -a, -A options
  17.         srchstring may be multiple with -m, -M, -y options
  18.         srchstring is disallowed with the numeric (-n) option
  19.         srchstring may be a file- list-of-searchterms - with -f option
  20.         srchstring may be a file- list-of-updates - with -B option
  21.         infile may not be wildcarded unless using dgw batch file (below)
  22.  
  23. *
  24. DESCRIPTION
  25.  
  26. dg will search a text file for a given phrase and print all "records" 
  27. containing that phrase to standard output. 
  28.  
  29. dg is intended for free form "flat" files of text containing records 
  30. (multi-line chunks or "paragraphs") separated by a defined delimiter 
  31. character (default is "*").  The delimiter character must occur at the 
  32. beginning of a line (but see options). Normally, no useful data should 
  33. be present ON the delimiter line, as it would be lost on output except 
  34. under certain options. 
  35.  
  36. A "paragraph" mode (-dd option) treats blank lines as record 
  37. delimiters. 
  38.  
  39. Unlike grep, which would report only the specific lines containing the 
  40. search term (or a fixed number of lines either side of the find), 
  41. data-grepper will print the entire record in which the search term was 
  42. found-- or a specified number of key lines for that record. 
  43.  
  44. The records of the data file are read in order, and records with 
  45. "hits" are sent to standard output.  Maximum line length is 200 
  46. (500 in UNIX versions). Overlong lines on input are tolerated, 
  47. but split to meet max line length.  dg has no limitations as to 
  48. record length, but the price paid is that it cannot accept standard 
  49. input from a pipe (the input file is opened twice). 
  50.  
  51. The program does not directly support wildcards, nor does it 
  52. understand all unix "regular expressions."  A wildcarded list of files 
  53. to search may be done using the dgw batch file. 
  54.  
  55. The searchstring is normally used literally on the command line, or, 
  56. by using the -f option, up to 100 searchstrings may be specified in a 
  57. separate file (100-DOS, 1000-UNIX).  Searchstring length is the same 
  58. as maximum linelength except when using the -f option, where 
  59. searchstring length is limited to 20. 
  60.  
  61.         dg  searchterm  file_to_search
  62.  
  63.         dg -f file_of_searchterms file_to_search
  64.  
  65. If the searchterm contains spaces, the searchterm must be enclosed in 
  66. single (UNIX) or double (DOS) quotes when used on the command line. 
  67.  
  68. Depending on options selected, the first 1-9 lines of each record may 
  69. be treated as key lines.  Either the search or the report or both may 
  70. be limited to these lines. 
  71.  
  72.         dg  -k3K5 searchterm  file_to_search
  73.  
  74.         will look for searchterm only in the first 3 lines of 
  75.         each record, and print the first 5 lines of records
  76.         when a match is found.
  77.  
  78. The output normally retains the "*" delimiters, thus becoming a subset 
  79. of the original data file, ready for further searches. 
  80.  
  81. Other single characters can be used as delimiters by specifying a new 
  82. delimiter on the command line. 
  83.  
  84.         dg  -d# searchterm  file_to_search
  85.  
  86.         will expect the # sign as record delimiter.
  87.  
  88. The special case ("paragraph mode"):
  89.  
  90.         dg  -dd searchterm  file_to_search
  91.  
  92.         will treat blank lines as record delimiters.
  93.  
  94.  
  95. There is an option for additional, secondary sub-delimiters (which may 
  96. be blank lines) if your data records are large enough to warrant this. 
  97.  
  98. Null records, those with only newlines between successive delimiter 
  99. lines, are ignored and will not be present on output.  
  100.  
  101. Records with whitespace (spaces, tabs) are not treated as nulls. 
  102.  
  103. The original delimiter lines are normally a single "*" character, but 
  104. may contain dashes or text following the delimiter character.  The 
  105. extra characters are treated as "comments" NOT to be printed on output 
  106. (unless the -R option is named).  Indeed, a whole series of delimiter-
  107. prefixed lines may be included in the master file as "comments" or 
  108. documentation, not to be printed on output. 
  109.  
  110. ---------------------------------------------------------------------------
  111. *
  112. OPTIONS  (in order of average overall usefulness)
  113.  
  114.  
  115.         -C         Case sensitive  (default is case insensitive).
  116.  
  117.         -c         Count only.  Report the number of records 
  118.                    containing the search phrase.
  119.  
  120.         -v         inVert sense.  Report records not containing 
  121.                    the search phrase.
  122.  
  123.         -d$        Use $ or other following char as Delimiter
  124.                    Exception:  Use -dd (yes - lower case d repeated)
  125.                    and the system will treat a blank line as the
  126.                    delimiter for search (sort of like considering
  127.                    paragraphs as records).  Output will, however,
  128.                    insert the standard "*" delimiter.
  129.  
  130.         -dd        Paragraph mode. Blank lines are record Delimiters.
  131.                    True blank lines only- no spaces or tabs.
  132.                    See -d above.
  133.  
  134.         -k[n]      Search in Keyword-lines-only. Declare the first n (1-9)
  135.                    lines as keyword-lines.  Default 1st line only.
  136.  
  137.         -K[n]      Limit output report to Keyword-lines-only.
  138.                    The first n (1-9) lines are Keyword-lines.  
  139.                    Default 1st line only.  n for -k and -K
  140.                    options limited to 1 digit.  They are 
  141.                    independent, and can be used together.
  142.  
  143.         -s         Status of data file: give record count only.
  144.                    If used with -V option, reports misc. file data.
  145.                    Ignores null records. (Reports them if verbose).
  146.                    (overrides other options on the command line)
  147.  
  148.         -l         Treat aLL records as hits. No searchterm needed.
  149.                    Useful with -D, -a, -A, -K options.
  150.                    dg -Kpl will give an undelimited list of
  151.                    first (key) lines. dg -Kplh# gives a similar
  152.                    list of major/minor keylines for files with
  153.                    major (*) records and sub(#)records. 
  154.                    Note- Other uses of -l and -h together are
  155.                    not recommended.
  156.  
  157.         -w         Match only on Words. (phrase bound by spaces 
  158.                    or line boundary or any non-alpha, non-digit)
  159.                    Underscore (_) is treated as part of a word.
  160.  
  161.         -u         Like -w but Underscore (_) is treated as a 
  162.                    word delimiter (as if whitespace) as well.
  163.  
  164.         -x         Search phrase is found even if it crosses over 
  165.                    a line boundary (X-over). One-line crossover 
  166.                    only. Ignores trailing but not leading 
  167.                    spaces on lines.  Best when used with -T 
  168.                    to ignore leading spaces too.  Note: trailing
  169.                    hyphens are also ignored so that normal word
  170.                    hyphenation is dealt with.
  171.  
  172.         -f         Get searchstrings from File.  
  173.                    Use filename to replace search phrase on the 
  174.                    command line.  Leading and trailing spaces in
  175.                    the file of phrases are stripped. For DOS, number of 
  176.                    searchstrings in the file is limited to 100 
  177.                    *and* a 20 character string size limit is imposed.
  178.                    Finds are reported in the order they occur in the 
  179.                    data file, not the order of the file of terms. 
  180.                    (use batch files/unix scripts if you must extract 
  181.                    records in other than data file order.) 
  182.  
  183.         -F[n]      The searchterm must be found in Field n of a
  184.                    line to be considered a hit.  Incompatible
  185.                    with -mMxnUD and ^$ usage.  A field of a line
  186.                    is defined as in a default awk usage-- words or 
  187.                    terms separated by whitespace, with leading/trailing 
  188.                    whitespace ignored.  Use -F with no numerics to 
  189.                    indicate the last field of a line regardless of
  190.                    the number of fields there.  See extended discussion
  191.                    below.
  192.  
  193.         -L         Affects -F option. Lax enforcement of field numbers
  194.                    and lengths.  See extended discussion below.
  195.  
  196.         -m[n]      Expect n Multiple search terms on the command line,
  197.                    each of which must be present on_a_single_line in a
  198.                    record to cause a find. If n is omitted, n=2.
  199.                    Incompatible with -v.  Max n is 9. If the searchterms
  200.                    are identical, 1 hit suffices.  If used with -x,
  201.                    finds must be within about 1 line of each other.
  202.  
  203.         -M[n]      Expect n Multiple search terms on the command line,
  204.                    each of which must be present somewhere_in_the_record 
  205.                    to cause a find. If n is omitted, n=2.
  206.                    Incompatible with -v.  Max n is 9.
  207.  
  208.         -E[n]      Look for Extras-- expect 1 search term on the command
  209.                    line, and report records having that term on at 
  210.                    least n separate lines. If n omitted, n=2.
  211.                    Incompatible with -v.  Looks for Extras.
  212.  
  213.         -p         Plain output.  Do not print the delimiter on output.
  214.                    Exception: with -y, kills only the sub-separator line.
  215.  
  216.         -e         Exact whole-line match required to cause a find.
  217.  
  218.         -T         Ignore L & R (lead/Trail) spaces on all lines. 
  219.                    Useful with  -e or -x                                        
  220.  
  221.         -Q         Quit on first find of term; on first find of *each* term
  222.                    when used with -f.  Useful with files that redundantly
  223.                    repeat records, e.g. expanded procedural flows. If more
  224.                    than one -f term is found in a record, all are satisfied
  225.                    by printing that record.  Do not confuse this with 
  226.                    -m or -M searches.  The -Q option then will quit on the
  227.                    first find satisfying the -m or -M condition.
  228.  
  229.         -W         Print only the record numbers where the finds occur.
  230.                    ("Which" records?)
  231.  
  232.         -h$        Use $ or other following char as an added, secondary 
  233.                    "Helper" delimiter. The secondary delimiter will be 
  234.                    recognized whether in the first or second position 
  235.                    on a line.  Output will be preceded by the first 
  236.                    line of the main record, and the phrase: "PARTIAL 
  237.                    RECORD:"  Not compatible with -x option.
  238.                    Exception:  Use -hh or terminal -h with no character
  239.                    specified, and the system will treat a virtual blank 
  240.                    line (true blank lines, or lines with only spaces/tabs)
  241.                    as a secondary delimiter for search (sort of like 
  242.                    considering paragraphs as sub-records within explicitly
  243.                    delimited records).  Output will, however, insert the 
  244.                    standard "*" delimiter. 
  245.                    Example:  dg -hhCF1 -h dgman
  246.                    will give help on the -h option of dg.
  247.  
  248.         -Dfname    Divide(distribute) output: 
  249.                    Write records found to files fname0001, fname0002...
  250.                    one file for each find. Supported ONLY as last option
  251.                    in the option list.  Limited to 9999 output files.
  252.  
  253.         -n#[...]   Get record by Number, e.g. -n456 = get 456th record
  254.                    Compatible ONLY with -vKqod$...  NOT with -aA
  255.                    Null records are ignored when counting.
  256.                    Supported ONLY as last option in the option list.
  257.                    A syntax of -n#[#####],#[#####] is supported to retrieve 
  258.                    a range of record numbers.  Particularly useful
  259.                    when a large file must be divided.
  260.  
  261.         -a         Print whole data file, Append contents of zzapfile 
  262.                    to finds. See discussion below: UPDATING RECORD STATUS
  263.  
  264.         -A         Print whole data file, Append zzapfile line 1 to 
  265.                    keyline 1 of finds. See discussion below: UPDATING 
  266.                    RECORD STATUS
  267.  
  268.         -j         Affects -a, -A options- don't print whole 
  269.                    file, but Just the records with finds.
  270.  
  271.         -J         Affects -a, -A options- tacks a "Jumped" record 
  272.                    number onto "found" records.
  273.  
  274.         -r         Print the delimiter followed by dashes (like a
  275.                    Ruler line) to enhance visual separation of records. 
  276.  
  277.         -R         Retain content of original delimiter lines.
  278.                    The default is to drop additional characters
  279.                    following the delimiter. (The default permits
  280.                    the delimiter line to contain "private" 
  281.                    file documentation.)
  282.  
  283.         -B         Fold-in Big data updates. Allows automated updates
  284.                    of large record sets based on a file of update
  285.                    directions.  Highly useful but only in limited
  286.                    circumstances.  See discussion below.
  287.  
  288.         -U         Uniqify a set of records. Directs deletion of 
  289.                    repeated records based solely on the last field of 
  290.                    the first keyline.  Limited filesizes except in
  291.                    UNIX versions. See extended discussion below. 
  292.  
  293.         -V         Verbose. Show prefatory/summary remarks.  Use 
  294.                    with -s for datafile status report. Use -Vq with
  295.                    dgw batch file to record filenames searched.
  296.  
  297.         -H         Emphasize the line in the record where the
  298.                    search conditions were met. Prints markers
  299.                    (happy faces if in DOS) at beginning of the 
  300.                    "Highlighted" line.  Seldom needed, but can be 
  301.                    helpful when individual records are long.
  302.  
  303.         -N         Print a Negative message if no records are found.
  304.                    Normally, there is no output when there are no 
  305.                    finds.
  306.  
  307.         -o         Null argument. Does nOthing. Useful from 
  308.                    some batch files/scripts. 
  309.  
  310.         -G         A Grep-like option. Only the lines with the
  311.                    match are printed.  Use only if a real grep is 
  312.                    unavailable. No REGEXP, but usable with the 
  313.                    following options: 
  314.                         -w, -u, -c, -v, -T, -C, -e, -f, -m, -F, -N, ^$
  315.                    Not usable with -k,-K,-x,-D,-Q,-y
  316.                    nor with most other options that are record-oriented.
  317.                    Inappropriate options are not all trapped, but 
  318.                    generally have no effect.
  319.  
  320.         -y         The grep-rest option. Unrelated to -G.
  321.                    "digs" for a record, Yet greps it too.
  322.                    Usable with -K such that IF a record is
  323.                    a "hit" the -K keylines are printed, and
  324.                    followed by any remaining lines in that record
  325.                    that contain one of a set of other searchterms.
  326.                    I.E.- print the keylines of finds and grep the
  327.                    rest of the record for other searchterms.
  328.                    The -m option and syntax must be used, but the
  329.                    the FIRST term given in -m syntax becomes the 
  330.                    SOLE record searchterm and all OTHER -m terms 
  331.                    become what we grep for after the keylines.
  332.                    Example:
  333.     
  334.                         dg -ykK2m3r gold melt boil elements
  335.     
  336.                    will print the 1st 2 keylines of records in the
  337.                    file "elements" having "gold" in the 1st keyline,
  338.                    and then print any remaining lines in the record 
  339.                    having the terms "melt" or "boil".  Use with 
  340.                    the -r option for best visual separation of 
  341.                    resultant records.
  342.  
  343.         -I         Ignore delimiter if repeated in place 2.
  344.                    i.e., if a line begins with ** then
  345.                    Treat it as just a text line, not a delimiter line.
  346.                    Useful with certain originals when you don't want
  347.                    to clean them up first.
  348.  
  349.         -S         Add delimiters (Stars) to a file. A delimiter line is
  350.                    added _before_ each line containing the search term.
  351.                    Use -Sf and a file of searchterms when appropriate.
  352.  
  353.         -P         Add delimiters (Post-stars) to a file. Like -S, 
  354.                    but delimiters are added _following_ each line 
  355.                    that is a hit.
  356.  
  357.         -q         Quiet.  No extraneous prefatory/summary remarks
  358.                    (default, but retained for historical reasons).
  359.                    Exception: Use -Vq with dgw batch file to record 
  360.                    filenames searched.
  361.  
  362.         -i[n]      Recognize an Indented delimiter anywhere in the first
  363.                    n characters (1-9) of a line.  Useful in delimiting
  364.                    code files when the delimiter must reside inside 
  365.                    a comment, e.g., 
  366.                    /* (c) , //* (c++) , #* (unix), ;* (lisp) , REM * (dos)
  367.                    Especially useful with -T to kill leading whitespace
  368.                    for files that have extensive indentation schemes.
  369.                    Thus a -Ti option allows #* to work with any amount
  370.                    of leading whitespace.
  371.  
  372.         -Z[Z][1]   FuZzy searches-- Look for approximate matches.     
  373.                    The -Z option uses a SOUNDEX algorithm that assumes
  374.                    the first letter of every word is unfuzzy. Use
  375.                    the -ZZ option to fuzz even the first letter,
  376.                    e.g., batter with a searchterm of "patter", but
  377.                    expect lots of false hits.  A Z1 option uses a stem
  378.                    algorithm that might find "silliness" when you 
  379.                    search for "silly". All three fuzzy approaches 
  380.                    are desperation moves, sometimes laughable.
  381.                    You may need the -H option to figure out which
  382.                    line caused the hit.  Expect "fuzzy" to be more
  383.                    like "hairy" or even "wooly" most of the time.
  384.        
  385.                    The SOUNDEX approach is an old classic, which gives 
  386.                    decent results when you must search with names or 
  387.                    commonly misspelled words such as nuclear and 
  388.                    personnel, but expect lots of extra drivel as well.  
  389.                    Only the first few syllables are checked.  If you're 
  390.                    curious, you can inspect the kind of coding produced 
  391.                    for any searchterm by adding a -N option using a 
  392.                    file you know will NOT produce a match.  The "not 
  393.                    found" report will show the soundex or stem code of 
  394.                    the searchterm.  Alternatively, add a -V verbose 
  395.                    option and wade through the whole mess. 
  396.        
  397.                    Expect junk results if you use small searchterms, 
  398.                    numeric searchterms, or searchterms that include 
  399.                    spaces or punctuation. The -w option is disallowed.  
  400.                    Although only words are really treated, there can be 
  401.                    no guarantee of a true wordmatch.  The -e option is 
  402.                    allowed, but a hit indicates exactness only in the 
  403.                    coding string, not in the actual text. All fuzzy 
  404.                    searches are automatically case-insensitive.
  405.  
  406.         -O         Show PrOgress-- when working very large files,
  407.                    print some sign of life every 1000 lines 
  408.                    to screen only.
  409.  
  410.         ^$         These are not command line options, but implied
  411.                    options nonetheless.  Though full unix regular 
  412.                    expressions are not supported, the ^ and $ 
  413.                    expressions are:
  414.      
  415.                           dg ^foo filename
  416.      
  417.                    means look for "foo" at the beginning of a line.
  418.      
  419.                    Similarly:
  420.                           foo$ means foo at the end of a line
  421.                           \^foo means search for literal "^foo"
  422.                           foo\$ means search for literal "foo$"
  423.                           Note that a search for ^RAT$ is designed to
  424.                              succeed on "RATCELLAR WITH RAT"
  425.                           Use -e for the unix sense of ^RAT$
  426.                              where the intent is SOL-phrase-EOL.
  427.  
  428.  
  429. ---------------------------------------------------------------------------
  430. *
  431. USAGE: General
  432.  
  433. This utility is not designed to replace full featured databases with 
  434. formal query languages. It is suitable for keeping utility files, such 
  435. as address or contact files or software requirements files, when the 
  436. purpose of the search is not to settle just for individual lines 
  437. containing the desired phrase, but to get the entire paragraph or 
  438. record.  It is like grep with some notion of context. 
  439.  
  440. It is useful from the command line, but most powerful when used in 
  441. batch files that grab a set of records and then do further processing 
  442. on them. 
  443.  
  444. While dg is oriented to asterisk-delimited text files, any single-
  445. character delimiter can be used, including blank lines. 
  446.  
  447. Given a data file of simple paragraphs separated by blank lines, dg 
  448. can behave as if the blank lines were the "asterisk" delimiters: 
  449.  
  450.         dg -dd searchterm datafile
  451.  
  452. The output will be asterisk-delimited, unless you add the -p (plain) 
  453. option. The blank lines must not have hidden spaces or tabs, unless 
  454. you use the -T option (trim lead/trail spaces/tabs) option as well. 
  455.  
  456. ----------------------------------------------------------------------
  457. *
  458. USAGE: Null Records
  459.  
  460. Null Records:
  461.         A record is "null" if it has no bytes or only line-ending
  462.         bytes. Null records are ignored for output, and when 
  463.         counting to find an Nth record.
  464.  
  465. Null Keyword lines.
  466.         The -sV option will report records that have no data on
  467.         keyword lines.
  468.  
  469. ----------------------------------------------------------------------
  470. *
  471. USAGE: With awk and grep in scripts
  472.  
  473. dg it was originally designed to work in concert with awk in scripts 
  474. or batch files-- working against initially unformatted text files. 
  475.  
  476.         An aside:  if you are not familiar with awk, you are
  477.         missing one of the best tools available for manipulating
  478.         text files.  Get a copy of Rob Duff's awk or the GNU
  479.         gawk for DOS.  It has almost all the power of PERL,
  480.         but when you read an awk scipt six months after you've
  481.         written it, you'll understand it.  PERL is best only for
  482.         folks who will use it every day.
  483.         
  484. Given a master file of records without explicit delimiters, an easily 
  485. designed awk script can place delimiters at appropriate places in a 
  486. temporary copy of the original file using either a simple or fairly 
  487. sophisticated set of guidelines.  dg is then used to do searches on 
  488. the temporary file.  If the master is updated, the awk script is re-
  489. run to update the temporary file. 
  490.  
  491. The dg -S or -P option can be used instead of an awk for very simple 
  492. cases. Or-- if you simply want to trade blank lines for "*" delimiters, 
  493. use a -ddl option; the output will have "*" delimiters where the blank 
  494. lines were.
  495.  
  496. If your primary data is in a commercial database, you may find it 
  497. useful to dump a subset of the database to a delimited ASCII file.  
  498. Then, for the rest of the day, you can dig at it with dg, directly or 
  499. from scripts, without needing to keep the (potentially memory-hogging 
  500. or licensed-user-limited) database software running. 
  501.  
  502. ----------------------------------------------------------------------
  503. *
  504. USAGE: If records have labeled lines
  505.  
  506. dg is powerful when used with grep against data files designed to have 
  507. a number of labeled lines or "slots" in each record. 
  508.  
  509. With a file such as:
  510.  
  511.         NAME:   John Jones
  512.         PHONE:  999-9999
  513.         UNIT:   T-44
  514.         EXPER:  C, C++, aerodynamics
  515.         ASSIGN: Rufus GUI modules
  516.         DUE:    JAN 95
  517.         *
  518.         NAME:   Jane Smith
  519.         PHONE:  999-8888
  520.         UNIT:   T-55
  521.         EXPER:  LISP, scheduling, traffic flow, NL
  522.         ASSIGN: Rufus NL interface
  523.         DUE:    FEB 95
  524.         *
  525.  
  526. a command line or script call such as:
  527.  
  528.         dg smith filename | grep EXPER 
  529.  
  530. would yield:
  531.  
  532.         EXPER:  LISP, scheduling, traffic flow, NL
  533.  
  534. or--
  535.         
  536.         dg -ykKm3 smith exper assign filename
  537.  
  538. would yield:
  539.  
  540.         NAME:   Jane Smith
  541.         ...................
  542.         EXPER:  LISP, scheduling, traffic flow, NL
  543.         ASSIGN: Rufus NL interface
  544.  
  545.  
  546. whereas:
  547.  
  548.         dg smith filename
  549.  
  550. alone would print smith's entire record.
  551.  
  552. ----------------------------------------------------------------------
  553. *
  554. USAGE:  AND searches
  555.  
  556. One can use a script that searches for records with the first term, 
  557. redirecting output to a temporary file-- which is then searched for 
  558. records with the second term 
  559.  
  560.         dg  phrase1 filename > temp
  561.         dg  phrase2 temp
  562.  
  563. Alternatively, use the -M option:
  564.  
  565.         dg  -M  phrase1 phrase2 filename
  566.         dg  -M4 phrase1 phrase2 phrase3 phrase4 filename
  567.  
  568. If the search is intended to "AND" multiple phrases on a _single_ line, 
  569. use the -m option.  This is particularly useful when, e.g., you want 
  570. to find records containing "DEC" but only if the "DEC" is on a 
  571. HARDWARE line and not on a MONTH or DATE line. 
  572.  
  573.                   dg -m DEC HARDWARE filename
  574.  
  575. ----------------------------------------------------------------------
  576. *
  577. USAGE:  OR searches
  578.  
  579. Put the set of searchterms if a file and use the -f option.
  580.  
  581. ----------------------------------------------------------------------
  582. *
  583. USAGE: Searching Multiple Files
  584.  
  585. There is no provision for wildcards in the datafile name.
  586.  
  587. Each datafile must be searched individually.  
  588.          (Use awk to create a script that calls dg against 
  589.           each of a list of datafiles.)
  590.  
  591. Alternatively, use the following batch file or its unix equivalent.
  592. Note that the results are always written to a file named ztempx,
  593. in the current working directory.  The batch file will complain if
  594. you try to search ALL (*.* or *) files in the current working
  595. directory since that would include the output ztempx file.
  596. If you must search ALL files in a directory (* or *.*), do so from
  597. a higher level directory.  dgw -o srchterm asubdir/*.*
  598. will work fine.
  599.  
  600. The dgw output will not name the file where finds are found,
  601. unless you include a -Vq option.  If you do that, dg will 
  602. insert a record naming each file searched.  To clean out those
  603. advisories, just use dg again with dg -kv "Searching file:" ztempx
  604. to get a "clean" set of results.
  605.  
  606.     ---------------------cut here -----------------------------------
  607.     @ECHO OFF
  608.     rem bat file to use dg with wildcarded list-of-files-to-search
  609.     rem usage dgw -dg_arguments searchterm [*.txt or ad.* etc.] 
  610.     rem note: a dg argument must be given, at least -o (a do-nothing)
  611.     rem note: always writes result to file named ztempx (and sends to more)
  612.     rem note: thus ztempx must not be in the scope of the wildcard
  613.     
  614.     IF "%1" == "" GOTO helps
  615.     IF "%3" == "" GOTO error
  616.     ECHO ======Executing the command dg %1 %2 %3 %4 %5 %6
  617.     ECHO ======Will overwrite ztempx
  618.     ECHO ======RETURN to continue, ctrl-C to quit
  619.     PAUSE
  620.     IF EXIST ztempx  DEL ztempx>NUL
  621.     rem if touch program not available, use: @REM redirect_to ztempx
  622.     rem touch ztempx
  623.     @REM >ztempx
  624.     
  625.     rem current setup for 6 total args: supports, e.g., up to -m3
  626.     rem its possible to send 11 arguments with, e.g., -m9
  627.     rem expand below to handle 11 if desired
  628.     if exist %6 goto six
  629.     if exist %5 goto five
  630.     if exist %4 goto four
  631.     if exist %3 goto three
  632.     
  633.     :six
  634.     FOR %%X IN (%6) do if %%X==ZTEMPX goto scope
  635.     FOR %%X IN (%6) DO COMMAND/C dg %1 %2 %3 %4 %5 %%X >> ztempx
  636.     goto didsearch
  637.     :five
  638.     FOR %%X IN (%5) do if %%X==ZTEMPX goto scope
  639.     FOR %%X IN (%5) DO COMMAND/C dg %1 %2 %3 %4 %%X >> ztempx
  640.     goto didsearch
  641.     :four
  642.     FOR %%X IN (%4) do if %%X==ZTEMPX goto scope
  643.     FOR %%X IN (%4) DO COMMAND/C dg %1 %2 %3 %%X >> ztempx
  644.     goto didsearch
  645.     :three
  646.     FOR %%X IN (%3) do if %%X==ZTEMPX goto scope
  647.     FOR %%X IN (%3) DO COMMAND/C dg %1 %2 %%X >> ztempx
  648.     goto didsearch
  649.     
  650.     :didsearch
  651.     
  652.     echo ================ FINDS: ===================================
  653.     TYPE ztempx | more
  654.     ECHO =========== Finds placed in file ztempx ===================
  655.     GOTO end
  656.     :scope
  657.     echo ERROR- the wildcard term includes the output file "ztempx"
  658.     goto paterror
  659.     :error
  660.     ECHO   dgw error.
  661.     :helps
  662.     ECHO   dgw is used to do a dg-search against a wildcard list-of-files.
  663.     ECHO   e.g. " dgw -Kp searchterm *.foo " 
  664.     ECHO   A dg argument must be used. Use -o for a do-nothing argument.
  665.     ECHO   e.g. " dgw -o  searchterm *.txt " 
  666.     :paterror
  667.     ECHO   The output of each search is written to file "ztempx"
  668.     ECHO   Be sure that the wildcard term cannot "see" the file tempx
  669.     ECHO   NAME.* or *.NAM is ok. But be in a separate directory to use * or *.*
  670.     ECHO   e.g., NOT "dgw -o  searchterm *.*" NOR "dgw -o  searchterm *"
  671.     ECHO   e.g., BUT "dgw -o  searchterm subdir/*.*" will work.
  672.     end
  673.  
  674.     ---------------------cut here -----------------------------------
  675.  
  676. ----------------------------------------------------------------------
  677. *
  678. USAGE: Creating Tailored Data Sets from A Master
  679.  
  680. I need to maintain a large set of test datasets.  For the actual test, 
  681. each must be an individual file, but maintenance is much easier if 
  682. they are all kept in a single master file.  Each message is delimited. 
  683. At test run, a script executes dg with the -D option, creating the 
  684. individual files of the targeted datasets, before executing the actual 
  685. tests that will act on the individual files. 
  686.  
  687. All datasets include one or more keywords such as "full", others 
  688. "fullminus", and others "specialcase4"; the keywords indicate the 
  689. class of test. Depending on need, a dg for the desired keyword 
  690. produces the tailored test set files. 
  691.  
  692. ----------------------------------------------------------------------
  693. *
  694. USAGE: Understanding the Multiple Terms Options ( -m, -M, -E, -y )
  695.  
  696. These options can be confusing, but each has been a lifesaver at one 
  697. time or another.  These examples may help: 
  698.  
  699.      dg -m  foo fum     filename - a hit if foo & fum on a single line
  700.      dg -m3 foo fum fay filename - a hit if all 3 on a single line
  701.      dg -M3 foo fum fay filename - a hit if all 3 anywhere in a record
  702.      dg -E3 foo filename         - a hit if foo is on at least 
  703.                                      3 separate lines in a record 
  704.  
  705. The following are not useful searches, but they help explain the 
  706. behavior when searchterms overlap: 
  707.  
  708.      dg -M3 foo foo foo filename - will succeed if 1 foo in a record
  709.      dg -m3 foo foo foo filename - will succeed if 1 foo in a line
  710.  
  711. The -y option needs an assist from the -m option in meeting the
  712. command line syntax, but the meaning of terms and behavior are very
  713. different.  Also, the -y option may be used only with a -K option.
  714.  
  715.      dg -yKm3 foo fum fay filename
  716.  
  717. For this case, "foo" becomes the sole searchterm determining
  718. whether a record is a hit.  For such records, the first keyline
  719. is printed (-K), and for the remainder of the record, any lines
  720. containing "fum" or "fay" will be printed.  The "m" in the options
  721. is used only to bring in the searchterms and then its "normal" meaning
  722. is ignored.
  723.  
  724. ----------------------------------------------------------------------
  725. *
  726. USAGE: Eliminating Dupes In Multiply Appended Results Files.
  727.  
  728. The -U option is generally useful only if you intend to search a large 
  729. set of records several times, appending each result to a collection 
  730. file.  Naturally this kind of job can result in a final file with 
  731. quite a few duplicate records. 
  732.  
  733. To avoid this, first run dg against the master file (or a copy therof) 
  734. with an -aJ option to append a record number to the first keyline of 
  735. each master record. 
  736.  
  737. Then run your multiple searches against this modified master, 
  738. appending the results of all searches to the collection file.  
  739. Finally, run dg with a  -U option to create a uniq'd final version. 
  740.  
  741. This option needs to build an array of last-fields "already seen." To 
  742. limit memory poblems in DOS, no one "last-field" may exceed 10 
  743. characters in length, and the total record size to be culled may not 
  744. exceed 200 records.  A simple awk can do the job for tougher cases.
  745.  
  746. ----------------------------------------------------------------------
  747. *
  748. USAGE: The -F Field Option
  749.  
  750. The field option is only rarely of use, but very powerful when needed. 
  751.  
  752. This option allows you to limit search actions to specific fields of a 
  753. line.  E.G., consider the command: 
  754.  
  755.         dg -F12k3 Elizabeth records
  756.  
  757. The F12 indicates that only field 12 of any line should be searched for 
  758. the searchterm.  The k3 would further limit the search to only the 
  759. first 3 lines of any record. 
  760.  
  761. A field is defined like a default "field" in awk-- words or terms 
  762. separated by whitespace, with leading/trailing whitespace ignored. 
  763.  
  764. The -F option requires some limitations on the the maximum field 
  765. length and maximum number of fields per line. For DOS, these limits 
  766. are 40 and 20. That is, no one field with a length over 40, nor more 
  767. than 20 "words" in any one line. 
  768.  
  769. The option is designed primarily for files in which ALL lines stay 
  770. within these limits.  Any field exceeding the max length will be 
  771. truncated to "fit" and a warning posted to the screen.  Any one line 
  772. exceeding the max number of fields will cause an error warning and the 
  773. program will terminate. 
  774.  
  775. This behavior can help detect unintended errors in the way the data 
  776. file was created-- if it was your intent to stay within the limits 
  777. given. 
  778.  
  779. For other cases, you may intend that only certain lines will be 
  780. "fielded" lines, and others should not be restricted.  Use the -L 
  781. "lax" option to kill the complaints (-LF).  Any field past the 20th will 
  782. just be ignored. Fields exceeding max length are quietly truncated. 
  783.  
  784. If -F is used with no numeric attached, the program assumes you intend 
  785. to search the LAST field of the line.  Behavior for this special case 
  786. will be correct even if the normal max number of fields is exceeded.  
  787. Total line length limits will still apply. 
  788.  
  789.  
  790. ----------------------------------------------------------------------
  791. *
  792. USAGE: Updating Record Status:
  793.  
  794. If there is a need to append one or more new lines to selected records 
  795. in a master file: 
  796.  
  797.         --   Put the append text in a file named zzapfile
  798.         --   Run dg with the -a option.
  799.         --   The entire file will be sent to stdout with the
  800.                 append text appended to records matching the 
  801.                 search text.            
  802.  
  803. If there is a need to append a phrase to the main key-word line of 
  804. selected records: 
  805.  
  806.         --   As above, but use the -A option.
  807.         --   The contents of line 1 of the zzapfile
  808.                 will be appended to the 1st line of records 
  809.                 matching the search text.
  810.  
  811. Use the -J option along with the -a or -A options to append as 
  812. described, but inhibit printing of records that do not have a match. 
  813.  
  814.  
  815. ----------------------------------------------------------------------
  816. *
  817. USAGE: Updating Records with the -B option
  818.  
  819. The -B option allows one to update certain kinds of record files from 
  820. a manually (or otherwise) produced update file.  This is usable only 
  821. with files that use line names at the start of each line. 
  822.  
  823. Such a file, the tgtfile, might hold records such as:
  824.  
  825.      john smith 
  826.      title: staff engineer
  827.      ssn: 999-999-9999
  828.      salary: 44444
  829.      hired: 960506
  830.      *
  831.  
  832. If one creates an update file, foldfile, such as:
  833.  
  834.      ann smith ~salary: 45555
  835.      john smith ~salary: 77777
  836.      pat kelly  ~salary: 33333
  837.      john smith ~ssn: 888-888-8888 
  838.  
  839. Then the command:
  840.  
  841.      dg -kB foldfile tgtfile > zz
  842.  
  843. would update john (and ann's and pat's) salaries, as well as john's 
  844. ssn, leaving other records untouched. If john  did NOT have a salary 
  845. line, it would be appended as a new line in his record. You can update 
  846. multiple elements about john from a single update file.  (The updated 
  847. results are in file zz; dg never changes the original record file.) 
  848.  
  849. The option assumes you will use unique key terms that will be found 
  850. only once in the designated number of keylines. For example, an 
  851. update file such as 
  852.  
  853.      smith ~salary: 45555
  854.      john ~ssn: 777-777-7777 
  855.      pat ~salary: 33333 
  856.  
  857. will update john smith's ssn or his salary but not both.  If "john 
  858. smith" were used instead, both lines would be updated. 
  859.  
  860. This is important to understand, especially if you tell the search to
  861. continue over more than one keyline (by using, e.g., -k3).  If a valid 
  862. hit is found in, say, keyline 2, then actions will be taken based on 
  863. that hit-- and only based on the first hit in that line.  If you 
  864. expected additional actions based on a second possible hit in keyline 
  865. 2 -- or a separate hit in keyline 3-- you will be disappointed.  
  866. The search looks no further than the first hit.
  867.  
  868. The line title (e.g., ~salary) is always case sensitive.  Use of the 
  869. -C option will make searches for the key term (e.g., john smith) also 
  870. case sensitive. 
  871.  
  872. Note that line title in the update line should be identical to the 
  873. one that is used in the file of records if you want to preserve the 
  874. original line name. Otherwise the updated record will take on the 
  875. line title provided in the update file. For example, john ~STATUS OK 
  876. -- will find and replace "STATUS----: BAD", but the new line would be 
  877. "STATUS OK" not "STATUS----: OK". 
  878.  
  879. Limitations:  The file will look for "john" only in the keylines 
  880. specified. You must use the -k[] option with the -B to designate how 
  881. many keylines are to be searched. A maximum of 20 data elements about 
  882. john can be used in the file of updates. Data in keyline 1 cannot be 
  883. changed.
  884.  
  885. In general, don't try to overwork this option.  Its fine for limited
  886. cases. For more complex work, use awk.
  887. ----------------------------------------------------------------------
  888. *
  889. USAGE: Non-ASCII Documents
  890.  
  891. dg works ONLY with ASCII files. If you are keeping your master records 
  892. using document publication software, files saved will normally be 
  893. in other than pure ASCII.  All need not be lost.  Most such software 
  894. allows saving a pure ascii version as well.
  895.  
  896. I've had to keep quite a few documents in ready-to-publish form
  897. using Framemaker or Interleaf.  Whenever edits are made, I simply 
  898. create an extra, updated ASCII version as well, either directly or 
  899. using an awk to strip out the formatting and graphics in the extra 
  900. copy. 
  901.  
  902. ----------------------------------------------------------------------
  903. *
  904. USAGE: Help
  905.  
  906. Typing dg with no arguments provides some cryptic help.
  907.  
  908. Use the dgh.bat batch file or an equivalent unix script to get a bit better 
  909. help on a particular option.  Replace the "\dg\dgman" with your own path to 
  910. the dgman file. 
  911.  
  912. With this batch file in your path, enter:
  913.  
  914.     dgh -y
  915.  
  916. to see the part of dgman that describes the -y option.
  917.  
  918. ALternatively, use the dghh.bat file (or equivalent) to get help using
  919. a likely keyword:
  920.  
  921.     dghh dash
  922.  
  923. will show help on the -r ruler line  option.  Replace the "\dg\dgops.sam"
  924. with your own path to that file.
  925.  
  926. Note: The dgman and dgops.sam files contain embedded spaces on certain 
  927. apparently blank lines to keep certain help sections together when using
  928. the -dd option.  For example, see the help for -y. 
  929. ----------------------------------------------------------------------
  930. *
  931. USAGE: Option Confusion
  932.  
  933. You can come up with a lot of different option combinations using dg.
  934. When you get some combination that does what you want, put it in a
  935. batch file or an alias command.  Let the computer do the remembering.
  936. The dg.bat file shown above is a good example of usage.
  937.  
  938. ----------------------------------------------------------------------
  939. *
  940. BEHAVIOR:  Treatment of Punctuation
  941.  
  942. DOS BEHAVIOR:   
  943.     In a searchterm, <>| must be quoted. The ; and " symbols can be in 
  944. a searchterm only if using the -f option. A backslash (\) may be in a 
  945. searchterm but must not immediately precede a double quote ("). The % 
  946. symbol can be in a searchterm only if using the -f option or using the 
  947. command line directly; from a DOS batch file, the % symbol would be 
  948. lost. 
  949.  
  950.  
  951. UNIX BEHAVIOR:
  952.     Generally less silly. If you must include punctuation in a searchterm,
  953. you may or may not need to use single quotes around the term.  Experiment.
  954.  
  955. ----------------------------------------------------------------------
  956. *
  957. BEHAVIOR:  "WORDSEARCH" (-w)
  958.  
  959. A searchterm "hit" meets -w wordmatch criteria as long as the hit:
  960.      -- is bound on left  by: SOL, non-alpha, non-digit, non-underscore
  961.      -- is bound on right by: EOL, non-alpha, non-digit, non-underscore
  962.          (except with -U option, where underscore IS treated as wordbreak)
  963.  
  964. A "word" bounded by punctuation remains a word. Thus !@#$wow#$&%  
  965. will qualify in a wordsearch for "wow".  SOL means "Start of Line" and
  966. EOL is the end.
  967.  
  968. ALSO-- digits or punctuation INSIDE the searchterm do not disqualify it 
  969. as a "word." For example, "walla6*%^walla7" can be a word "hit" for 
  970. the "word" "walla6*%^walla7" since wordmatch only checks the area left &
  971. right of the "hit." 
  972.  
  973. ----------------------------------------------------------------------
  974. *
  975. BEHAVIOR:  UNPRINTABLE CHARACTERS:
  976.  
  977. The program is not designed to deal with control characters nor high-
  978. bit ASCII above 127 in the text nor the searchterms.  Consider the 
  979. behavior unpredictable when these are present. 
  980.  
  981. ----------------------------------------------------------------------
  982. *
  983. EXAMPLES
  984.  
  985. --- Random Files:
  986. The simplest example uses are for keeping randomly organized address 
  987. or contact records, system/software requirements statements, multi-
  988. line quotations or references, mini-help files, to-do files, scheduled 
  989. appointments, descriptions of hobby collectibles, recipes, or simply 
  990. random ideas.  Just separate all "data chunks" with a "*" delimiter. 
  991.  
  992. --- Unordered ASCII Documents (Paragraph Mode):
  993. Any documentation you reference often, or need to extract from, can be 
  994. dg-searched to get the right "paragraphs" to standard output, even if 
  995. the only delimiters are blank lines. 
  996.  
  997.         dg -dd phrase filename
  998.  
  999.         Will provide all paragraphs holding the phrase, and
  1000.  
  1001.         dg -vdd phrase filename
  1002.  
  1003.         Will provide all paragraphs NOT holding the phrase.
  1004.  
  1005.  
  1006. --- Master Documents with Summary Lists    (Advanced usage)
  1007. Often a master document of, say, software trouble reports, can be 
  1008. delimited and then searched for related topics.  The master may be a 
  1009. manually-maintained one or the ASCII result of a database query. 
  1010.  
  1011.         Item: A22
  1012.         Block:  Control
  1013.         Date:   940522
  1014.         Short_Title:    Foo fum
  1015.         Description:  This item is not performing correctly whenever 
  1016.         the input is made on a Tuesday before 2:15 PM.  Behavior normal
  1017.         at all other times.
  1018.         Supply Data:  Acme Co. and Ray-Bolixer Inc.
  1019.         Priority:     3
  1020.         Asssigned:    Joe
  1021.         Due           940610
  1022.         *
  1023.         Item:   A33
  1024.         etc.
  1025.  
  1026.         *
  1027.  
  1028.  
  1029. Perhaps you've created a priorities listfile from it, that you use to 
  1030. keep track of the big picture: 
  1031.  
  1032. Item    Block    Date    Short_Title     Priority    Assigned to   Due
  1033. A22     Control  940522  Foo_fum         3           Joe           940610
  1034. A33     Charts   940527  Fum_fee         2           Jane          940616
  1035. A44     A-Object 940528  Fee_fie         4           Joe           940622
  1036. A55     Control  940530  Fo_fum          1           Dan           940604
  1037.  
  1038. Assuming the Block designation is in one of the first, say 3, keylines 
  1039. of each record, try this: 
  1040.  
  1041. gawk '$2=="Control"{print "dg -k3 " $1 " > temp2.bat"}' listfile  > temp1.bat
  1042. call temp1  (creates temp2.bat)
  1043. call temp2
  1044.  
  1045. The awk creates a batch file of dg calls that will give you the 
  1046. details on the Control block problems.  Of course, if the records are 
  1047. in a full-fledged database, you could query it directly.  The dg 
  1048. approach is primarily of value in batch files/scripts-- especially if 
  1049. the data source is not worth entering or maintaining in a full fledged 
  1050. database system. 
  1051.  
  1052. ----------------------------------------------------------------------
  1053. *
  1054. SEE ALSO
  1055.      grep, awk, sed
  1056.  
  1057. ----------------------------------------------------------------------
  1058. *
  1059. BUGS & LIMITATIONS
  1060.  
  1061. Max line length in input file:           200 (500 in unix versions)
  1062. Max searchstring length:                 200 (500 in unix versions)
  1063. Max num of searchterms in -f searchfile: 100 (1000 in unix versions)
  1064.    Max searchstring length with -f:       20 (500 in unix versions)
  1065. Max number of fields for -F options       20 (100 in unix versions)
  1066. Max field length for -x, -F options       40 (100 in unix versions)
  1067. Maximum number of records 
  1068.    when killing dupes:                   200 (500 in unix versions)
  1069.  
  1070. Overlong lines on input are tolerated, but truncated as far as the 
  1071. search is concerned.  
  1072.  
  1073. Error management for insensible option combinations is provided only 
  1074. for the most common mismatches. 
  1075.  
  1076. LIMITATION: Use of a file of searchterms:
  1077.  
  1078. The -f option provides results only in the order that hits occur in 
  1079. the original data file.  Getting results in the order listed in the 
  1080. list of search terms could be useful. 
  1081.  
  1082.       Use the following awk & script approach as a workaround:
  1083.  
  1084.       Create the list of search terms as "srchtrms"
  1085.       Use of dg -f srchterms datafile would give
  1086.          results in the order of the terms found in datafile.
  1087.       To get results in the order of terms in srchterms, use
  1088.       awk -f thisawkfile srchterms > temp.bat
  1089.       Run the resulting temp.bat file.  
  1090.       Results will be in "results.txt"
  1091.       thisawkfile:
  1092.           BEGIN{
  1093.           #assuming  the datafile is "datafile"
  1094.           #and file of searchterms is "srchterms"
  1095.           datafile= "datafile"
  1096.           #following for dos, use 39 (') for unix
  1097.           q = sprintf("%c",34)
  1098.           print "del results.txt"
  1099.           #unix only:  print "touch results.txt"
  1100.           }
  1101.           #main
  1102.           {print "dg -k " q $0 q " " datafile " >> results.txt"
  1103.            #above commands are printed to temp.bat when
  1104.            #called as awk -f thisawkfile srchterms > temp.bat
  1105.           }
  1106.  
  1107. LIMITATION No Pipe capability TO dg:
  1108.  
  1109. The inability to accept input from a pipe can be annoying, but was a 
  1110. tradeoff for efficiency.  The program opens the input file twice using 
  1111. the first file tag to do the searching, with the second tag playing a 
  1112. "follower" role to print records that are "finds."  This approach 
  1113. avoids the need for large memory allocations, thus allowing unlimited 
  1114. record lengths.  Unfortunately stdin cannot be "opened twice," thus 
  1115. piping the output of other commands to dg has been sacrificed to avoid 
  1116. record size limitations. OUTput from dg can be redirected through a pipe.
  1117.  
  1118. Bugs:
  1119.  
  1120. Certainly.  Let me know what you find.
  1121.  
  1122. -- Pete Marikle
  1123. ----------------------------------------------------------------------
  1124. *
  1125.  
  1126.